package bsi.vn.FirstApp;

import java.util.ArrayList;

import bsi.vn.Data.ErrorListAdapter;
import bsi.vn.Data.ErrorListData;
import bsi.vn.Lib.ProcessFunc;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class ReferenceActivity extends Activity {
	private ArrayList<ErrorListData> myErrorList = new ArrayList<ErrorListData>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_reference);
		myErrorList = ProcessFunc.GetErrorList(ReferenceActivity.this);
		final ListView lv1 = (ListView) findViewById(R.id.ellvErrorList);
		lv1.setAdapter(new ErrorListAdapter(ReferenceActivity.this, myErrorList));

		lv1.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				int ErrorId = myErrorList.get(position).getErrorId();
				String ErrorCode = myErrorList.get(position).getErrorCode();
				Intent i = new Intent(getApplicationContext(),
						ErrorDetailActivity.class);
				i.putExtra("ErrorId", ErrorId);
				i.putExtra("ErrorCode", ErrorCode);
				startActivity(i);
			}
		});
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater menuInflater = getMenuInflater();
		menuInflater.inflate(R.menu.atmsearch, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() != R.id.menu_sub && item.getItemId() != R.id.menu_reference) {
			startActivity(ProcessFunc.MenuAction(this, item));
		}
		return true;
	}

}
